<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@	page import="com.yaodian100.core.common.utils.ServerValue"%>
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath()%>'/>
<!-- 月历 -->
	<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick.js"></script>
	<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick-zh-CN.js"></script>
	<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css"/>
<!-- 数字验证 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.alphanumeric.js"></script>
<script language="javascript">
	$().ready( function() {
		$('#startDate').datepick({minDate: new Date(), showOn: 'both',numberOfMonths:2,
	    	buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd",yearRange: '-50:+50'});
		$('#endDate').datepick({minDate: new Date(), showOn: 'both', numberOfMonths:2,
	    	buttonImageOnly: true, beforeShow:customRange, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd",yearRange: '-50:+50'});
		function customRange (){
			var startDt = $('#startDate').val(); //起始日
			var endDt = new Date(parseInt(startDt.substring(0,4),10),parseInt(startDt.substring(5,7),10)-1,parseInt(startDt.substring(8,10),10)); //結束日
			return {minDate:endDt}; 
		}
		$("#submit_button").click(function(){
			if ( $("#name").val() == "" ){
				alert("请输入问卷名称");
				return false;
			}
			if ( $("#startDate").val() == "" ){
				alert("请输入起始日期");
				return false;
			}
			if ( $("#endDate").val() == "" ){
				alert("请输入结束日期");
				return false;
			}			
			if ( $.trim($('#template').val()).length==0 ){
				alert("请输入template内容");
				return false;
			}
			$("#surveyForm").submit();
		});
	});
</script>
<style type="text/css">
.msg{float:left; line-height:1em; margin:0; display:block;border:1px solid #f66;padding:2px 5px;*padding:2px 5px 1px;}
.msg.rn{background-color:#fff2f2;border-color:#f66;}
</style>
<s:if test="hasActionErrors()">
	<s:actionerror cssClass="msg rn"/>
</s:if>
<s:if test="hasActionMessages()">
	<s:actionmessage cssClass="msg rn"/>
</s:if>
<p></p>
<h1>问卷管理<br/>
<div class="f-link">
	<a href="${midContextPath}/survey/search.do">回问卷查詢页</a>
</div>
</h1>
<s:form action="save.do" method="post" id="surveyForm">
	<table class="tb-data" width="100%">
		<tr>
			<th>问卷代码</th>
			<td>
				<c-rt:choose>
					<c-rt:when test="${empty id}">系统产生</c-rt:when>
					<c-rt:otherwise>${id}</c-rt:otherwise>
				</c-rt:choose>
			</td>
		</tr>
		<tr>
			<th>*问卷名稱</th>
			<td>
				<input type="text" name="name" id="name" value="${survey.name}" maxlength="20"/>
			</td>
		</tr>
		<tr>
			<th>*起始日期</th>
			<td>
				<s:date name="%{survey.startDate}" format="yyyy-MM-dd" var="fmtStartDate"/>
				<input type="text" name="startDate" id="startDate" value="${fmtStartDate}" readonly="readonly"/>
			</td>
		</tr>
		<tr>
			<th>*结束日期</th>
			<td>
				<s:date name="%{survey.endDate}" format="yyyy-MM-dd" var="fmtEndDate"/>
				<input type="text" name="endDate" id="endDate" value="${fmtEndDate}" readonly="readonly"/>
			</td>
		</tr>
		<tr>
			<th>*template</th>
			<td>
				<textarea rows="10" cols="120" id="template" name="template">${fn:escapeXml(survey.template)}</textarea>
			</td>
		</tr>
	</table>
	<p></p>
	<table class="tb-data" width="100%">
		<c-rt:forEach begin="1" end="30" var="i" step="2">
			<tr>
				<th>问题${i}</th>
				<td>
				<c-rt:set var="mapName" value="coName${i}"/>
					<input type="text" name="coName${i}" id="coName${i}" maxlength="20" value="${coNameMap[mapName] }"/>
				</td>
				<c-rt:set var = "i" value="${i+1}"/>
				<c-rt:set var="mapName" value="coName${i}"/>
				<th>问题${i}</th>
				<td>
					<input type="text" name="coName${i}" id="coName${i}" maxlength="20" value="${coNameMap[mapName] }"/>
				</td>			
			</tr>	
		</c-rt:forEach>
	</table>
	<input type="button" id="submit_button" value="送出"/>
	<input type="button" onclick="this.form.action='${midContextPath}/survey/search.do';this.form.submit();" value="Cancel"/>
</s:form>
